// middleware/validation.js
const Joi = require('joi');

const schema = Joi.object({
  city: Joi.string().min(2).required(),
  units: Joi.string().valid('metric', 'imperial').default('metric'),
  lang: Joi.string().valid('en', 'zh_cn').default('en')
});

module.exports = (req, res, next) => {
  const { error } = schema.validate(req.query);
  if (error) return res.status(400).json({ 
    error: error.details[0].message.replace(/"/g, '') 
  });
  next();
};